var mapSize = [4096,2096];
//var paper = Raphael(0, 0, 4096, 2048);


var selectControl = new function() {
	
	this.requestSelect = function(requester) {
		if(window.selectedSoldier!=requester) {
			window.selectedSoldier.deselected();
		}
		window.selectedSoldier = requester;
		requester.selected();
	};
	
}();
	


var collisionMap;
var losMap;
var canvas;
$("document").ready( function() {
	collisionMap = new CollisionMap();
	losMap = new losMap();

	canvas = $("canvas")[0];
	var soldier1 = new Soldier("red");
	var soldier2 = new Soldier("blue");

//	$("#canvas").width(mapSize[0]+"px");
//	$("#canvas").height(mapSize[1]+"px");
//	$("#canvas").css("border"," 1px solid black")

	soldier1.selected();
	window.selectedSoldier = soldier1;
	
	function moveTo(event) {
		var posX = event.pageX;
		var posY = event.pageY;
		window.selectedSoldier.moveTo(posX, posY);
	}
	
	
	var mouseIsDown = false;
	
	$("#canvas").on("mousedown",function(event){
		event.preventDefault();

		mouseIsDown = true;
		moveTo(event);
	});
	
	$("#canvas").on("mouseup",function(event){
		event.preventDefault();

		mouseIsDown = false;
		moveTo(event);
		
	});
	var okToReceiveMouseMove = true;
	
	var timer;
	$("#canvas").on('mousemove',function(event) {
		if(mouseIsDown) {
			if(okToReceiveMouseMove) {
				okToReceiveMouseMove = false;
				clearTimeout(timer);
				timer = setTimeout(function() {okToReceiveMouseMove = true;},100)
				moveTo(event);
			}
		}
		
		event.preventDefault();
	});

	
});

